﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Frame.DataHelper;
using System.Data;
using System.Data.Linq;

namespace Frame.Global
{
    /// <summary>
    /// 公共属性集合类
    /// 此类中的所有属性皆为静态
    /// </summary>
    public abstract class GlobalRunParms
    {
        #region 页面相关属性

        /// <summary>
        /// 全局删除按钮控制(by SU)
        /// </summary>
        public static string GlobalDelete
        {
            get { return ConfigurationManager.AppSettings["GlobalDelete"] != null ? ConfigurationManager.AppSettings["GlobalDelete"].ToString() : "Y"; }
        }

        /// <summary>
        /// EditForm编辑项回车事件调用JS方法名(无参数,无括号)(by SU)
        /// </summary>
        public static string EditorEnterEventName
        {
            get { return ConfigurationManager.AppSettings["EnterEvent"] != null ? ConfigurationManager.AppSettings["EnterEvent"].ToString() : ""; }
        }

        /// <summary>
        /// GridView设置图片按钮(by SU)
        /// </summary>
        public static string IsImageButton
        {
            get { return ConfigurationManager.AppSettings["IsImageButton"] != null ? ConfigurationManager.AppSettings["IsImageButton"].ToString() : ""; }
        }

        /// <summary>
        /// GridView新增按钮图片(by SU)
        /// </summary>
        public static string AddIcon
        {
            get { return ConfigurationManager.AppSettings["AddIcon"] != null ? ConfigurationManager.AppSettings["AddIcon"].ToString() : ""; }
        }

        /// <summary>
        /// GridView编辑按钮图片(by SU)
        /// </summary>
        public static string EditIcon
        {
            get { return ConfigurationManager.AppSettings["EditIcon"] != null ? ConfigurationManager.AppSettings["EditIcon"].ToString() : ""; }
        }

        /// <summary>
        /// GridView删除按钮图片(by SU)
        /// </summary>
        public static string DeleteIcon
        {
            get { return ConfigurationManager.AppSettings["DeleteIcon"] != null ? ConfigurationManager.AppSettings["DeleteIcon"].ToString() : ""; }
        }
        /// <summary>
        /// GridView查询按钮图片(by SU)
        /// </summary>
        public static string QueryIcon
        {
            get { return ConfigurationManager.AppSettings["QueryIcon"] != null ? ConfigurationManager.AppSettings["QueryIcon"].ToString() : ""; }
        }

        /// <summary>
        /// EditForm更新按钮图片(by SU)
        /// </summary>
        public static string UpdateIcon
        {
            get { return ConfigurationManager.AppSettings["UpdateIcon"] != null ? ConfigurationManager.AppSettings["UpdateIcon"].ToString() : ""; }
        }

        /// <summary>
        /// EditForm取消按钮图片(by SU)
        /// </summary>
        public static string CancelIcon
        {
            get { return ConfigurationManager.AppSettings["CancelIcon"] != null ? ConfigurationManager.AppSettings["CancelIcon"].ToString() : ""; }
        }

        /// <summary>
        /// 过滤行的条件清除按钮图片(by SU)
        /// </summary>
        public static string ClearIcon
        {
            get { return ConfigurationManager.AppSettings["ClearIcon"] != null ? ConfigurationManager.AppSettings["ClearIcon"].ToString() : ""; }
        }
        #endregion

        #region 数据库相关属性 (DataBase Propertys)
        /// <summary>
        /// 在web.config中数据库连接的链接名
        /// </summary>
        static string PubdataConnctionToken
        {
            get { return "CMSConnectionString"; }
        }
        /// <summary>
        /// 主数据库字符串
        /// </summary>
        public static string PubdataConncetionString
        {
            get { return ConfigurationManager.ConnectionStrings[PubdataConnctionToken].ToString(); }
        }
        /// <summary>
        /// 主数据库链接
        /// </summary>
        public static SqlConnection PubdataConncetion
        {
            get
            {
                SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings[PubdataConnctionToken].ToString());
                sqlcon.Open();
                return sqlcon;
            }
        }
        /// <summary>
        /// 获取默认数据上下文对象
        /// </summary>
        /// <returns></returns>
        public static DataContext GetDefaultDataContext()
        {
            DataContext context = new DataContext(PubdataConncetionString);
            return context;
        }

        #endregion

        #region 获取系统名称
        ///<summary>
        /// 系统启动后的系统名称，在css_sysinfo中
        ///</summary>
        ///
        public static string SystemName
        {
            get
            {
                string sqlstr = "select sm from sm_sysinfo where xm='systemname'";
                try
                {
                    return CssSQLHelper.CssExecuteScalar(PubdataConncetionString, CommandType.Text, sqlstr, null).ToString();
                }
                catch
                {
                    throw new Exception("浙江中软信息工程有限公司");
                }
            }
        }
        #endregion


        #region Url路径相关属性 (Url Propertys)
        /// <summary>
        /// 网站相对主目录路径
        /// 包含登录页，主页，报错页等的主文件夹。
        /// </summary>
        public static string WebPath
        {
            get
            {
                string sqlstr = "select sm from sm_sysinfo where xm='webpath'";
                try
                {
                    return CssSQLHelper.CssExecuteScalar(PubdataConncetionString, CommandType.Text, sqlstr, null).ToString();
                }
                catch
                {
                    throw new Exception("无法定位网站路径！请联系管理员！");
                }
            }
        }
        /// <summary>
        /// 用于记录登录页所载的详细路径(相对于网站主文件夹的路径)
        /// </summary>
        public static string LoginPagePath
        {
            get
            {
                if (ConfigurationManager.AppSettings["WebLoginPath"] != null)
                {
                    return ConfigurationManager.AppSettings["WebLoginPath"];
                }
                else
                {
                    return "~\\" + "login.aspx";
                }
            }
        }
        /// <summary>
        /// 用于记录主页所载的详细路径(相对于网站主文件夹的路径)
        /// </summary>
        public static string MainPagePath
        {
            get
            {

                return WebPath + "main.aspx";
            }
        }
        /// <summary>
        /// 用于记录报错页所载的详细路径(相对于网站主文件夹的路径)
        /// </summary>
        public static string ErrorPagePath
        {
            get
            {
                if (ConfigurationManager.AppSettings["WebErrorPath"] != null)
                {
                    return ConfigurationManager.AppSettings["WebErrorPath"];
                }
                else
                {
                    return "~\\" + "error.aspx";
                }
            }
        }
        #endregion

        #region 全局Debug相关属性 Global Debug Propertys
        /// <summary>
        /// 系统是否处于Trace模式
        /// </summary>
        public static bool EnableTrace
        {
            get
            {
                string sqlstr = "select sm from sm_sysinfo where xm='Enabletrace'";
                try
                {
                    if (GlobalSqlHelper.ExcuteSQLScalar(sqlstr).ToString() == "On")
                    {
                        return true;
                    }
                    else return false;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        #endregion
    }
}


